﻿Imports MbUnit.Framework
Imports System.Configuration
Imports FM.NetBouncer

''' <summary>
''' Configuration based initilasition tests
''' </summary>
<TestFixture()> _
Public Class ConfigurationFixture
    <Test()> _
    Public Sub Test()
        'Assert.AreEqual(RuleConfiguration.Settings.Test, "xxx")
        'RuleConfiguration.Settings.Test = "test"
        Dim Bouncer As NetBouncer = CType(ConfigurationManager.GetSection("NetBouncer"), NetBouncer)
        Console.WriteLine("Out : " & Bouncer.RuleSets.Count)

        For Each RSet As RuleSet(Of String) In Bouncer.RuleSets
            Console.WriteLine(RSet.Name)
        Next

    End Sub


    <RowTest()> _
    <Row("10", "", True)> _
    <Row("-10", "", False)> _
    <Row("10a", "", False)> _
    Public Sub IsPositiveIntegerRuleset(ByVal input As String, ByVal desc As String, ByVal expectedType As Boolean)

        Dim Bouncer As NetBouncer = CType(ConfigurationManager.GetSection("NetBouncer"), NetBouncer)
        Console.WriteLine("Out : " & Bouncer.RuleSets.Count)

        Dim X As New BaseParameter(Of String, String)(input, Bouncer.RuleSets("UnitTest-PositiveInteger"))
        Assert.AreEqual(X.IsValid, expectedType, desc)
    End Sub

    <Test()> _
    Public Sub NestedElements()

        Dim Bouncer As NetBouncer = CType(ConfigurationManager.GetSection("NetBouncer"), NetBouncer)
        Console.WriteLine("Out : " & Bouncer.RuleSets.Count)

        For Each RSet As RuleSet(Of String) In Bouncer.RuleSets
            For Each Rule As IRule(Of String) In RSet.Rules
                Console.WriteLine(Rule.ToString)
            Next
        Next

    End Sub

    <Test()> _
    Public Sub WhiteListDefaultPattern()
        Dim Test As New Parameter("abc", NetBouncer.RuleSet("UnitTest1-WhiteListDefault"))
        Assert.IsTrue(Test.IsValid())
    End Sub

    <Test()> _
    Public Sub WhiteListDefaultPatternInvalid()
        Dim Test As New Parameter("abxc", NetBouncer.RuleSet("UnitTest1-WhiteListDefault"))
        Assert.IsFalse(Test.IsValid())
    End Sub



    <RowTest()> _
    <Row("abcdefg", "", True)> _
    <Row("abc", "", False)> _
    <Row(Nothing, "", False)> _
    <Row("123456", "", False)> _
    <Row("abcdefgf", "", True)> _
    <Row("abcdefgfhhhhhhhhhh", "", False)> _
    Public Sub RuleSetBase(ByVal input As String, ByVal desc As String, ByVal expectedType As Boolean)

        Dim Test As New Parameter(input, NetBouncer.RuleSet("UnitTest-Base"))
        Assert.AreEqual(Test.IsValid(), expectedType, desc)

    End Sub

    '    <Test()> _
    '    Public Sub WhiteListCustomPattern()
    '        Dim Test As New Parameter("abc")

    '        Dim WhiteListC As New RuleSet(Of String)
    '        Dim WR As New Rules.WhiteListCharacters()

    'Test.RuleSet = 
    '        Assert.IsTrue(Test.IsValid())
    '    End Sub

End Class
